package cn.exrick.xboot.modules.assessment.controller;

import cn.exrick.xboot.base.XbootBaseController;
import cn.exrick.xboot.common.utils.CustomPage;
import cn.exrick.xboot.common.utils.PageUtil;
import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.PageVo;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.common.vo.SearchVo;
import cn.exrick.xboot.flow.entity.FlowInstanceinfo;
import cn.exrick.xboot.flow.mapper.FlowInstanceinfoMapper;
import cn.exrick.xboot.flow.service.IFlowInstanceinfoService;
import cn.exrick.xboot.modules.assessment.entity.HkAssessmentInfo;
import cn.exrick.xboot.modules.assessment.service.HkAssessmentInfoService;
import cn.exrick.xboot.modules.assessment.vo.HkAssessmentInfoAndFlowQueryVo;
import cn.exrick.xboot.modules.assessment.vo.HkassessmentScoreAndRecordVo;
import cn.exrick.xboot.modules.assessment.vo.ItemAndProcessIdVo;
import cn.exrick.xboot.modules.assessment.vo.ScoreAndCommentHistoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @author yck
 */
@Slf4j
@RestController
@Api(description = "绩效信息表管理接口")
@RequestMapping("/xboot/hkAssessmentInfo")
@Transactional
public class HkAssessmentInfoController extends XbootBaseController<HkAssessmentInfo, String> {

    @Autowired
    private HkAssessmentInfoService hkAssessmentInfoService;
    @Autowired
    private FlowInstanceinfoMapper flowInstanceinfoMapper;

    @Override
    public HkAssessmentInfoService getService() {
        return hkAssessmentInfoService;
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<HkAssessmentInfo>> getByCondition(HkAssessmentInfo hkAssessmentInfo,
                                                            SearchVo searchVo,
                                                            PageVo pageVo){

        Page<HkAssessmentInfo> page = hkAssessmentInfoService.findByCondition(hkAssessmentInfo, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<HkAssessmentInfo>>().setData(page);
    }

    /*
    *HkAssessmentInfoAndFlowQueryVo
    * */
    @RequestMapping(value = "/getHkAssessmentInfoAndFlow", method = RequestMethod.GET)
    public Result getHkAssessmentInfoAndFlow( HkAssessmentInfoAndFlowQueryVo vo){
     CustomPage page=   hkAssessmentInfoService.getHkAssessmentInfoAndFlow(vo);
        return  ResultUtil.data(page);
    }
    /*
    *
    * 活动列表详情页
    * */
    @RequestMapping(value = "/getHkAssessmentScoreDetial", method = RequestMethod.GET)
    public Result getHkAssessmentScoreDetial( String processInstanceId){
        HkassessmentScoreAndRecordVo vos=   hkAssessmentInfoService.getHkAssessmentScoreDetial(processInstanceId);


        return  ResultUtil.data(vos);
    }
    /*
    * 考核项考核记录
    * */
    @RequestMapping(value = "/getItemScoreAndCommentHistory", method = RequestMethod.GET)
    public Result getItemScoreAndCommentHistory(ItemAndProcessIdVo vo){
       List<ScoreAndCommentHistoryVo> vos=   hkAssessmentInfoService.getItemScoreAndCommentHistory(vo);
        return  ResultUtil.data(vos);
    }
    /**
     * 同步流程id
     */
    @RequestMapping(value = "/synchronizationTemplateId", method = RequestMethod.GET)
    public Result synchronizationTemplateId(){
        try {
            hkAssessmentInfoService.synchronizationTemplateId();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }


        return  ResultUtil.data("同步完成");
    }
}
